#include "text.h"
#include <osgDB/ReadFile>
#include <iostream>
#include <osg/Vec3d>

//----------------------------------------------------------------------
Text::~Text(void)
//----------------------------------------------------------------------
{
}
//----------------------------------------------------------------------
void Text::Init(std::string text)
//----------------------------------------------------------------------
{
  _transform->removeChild(_node.get());
  _node =0;

  _text = new  osgText::Text();
  _text->setText(text);
  _text->setFont("fonts/arial.ttf");
  _text->setCharacterSizeMode(osgText::Text::CharacterSizeMode::SCREEN_COORDS);

  _geode = new osg::Geode();
  _geode->addDrawable( _text.get() );
    osg::StateSet* ss = _geode->getOrCreateStateSet();
    ss->setMode(GL_LIGHTING,osg::StateAttribute::OFF);

  _cam = new osg::Camera();
  _cam->setProjectionMatrix(osg::Matrix::ortho2D(-640,640,-480,480));
  _cam->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
  _cam->setViewMatrix(osg::Matrix::identity());
  _cam->setClearMask(GL_DEPTH_BUFFER_BIT);
  _cam->setRenderOrder(osg::Camera::POST_RENDER);
  _cam->addChild(_geode.get());

  _transform->addChild( _cam.get() );
}

/*
//----------------------------------------------------------------------
void Node::Move(  Vec p )
//----------------------------------------------------------------------
{
  Decompose();
  _trans += p.Get();
  Ricompose();
}
//----------------------------------------------------------------------
std::string Node::Repr()
//----------------------------------------------------------------------
{
  std::ostringstream p; 
  if (_parent) p << "'node" << _parent->_id << "'"; else p << "none";

  std::ostringstream os; 
  os << "id      = " << "'node" << _id << "'" << std::endl;
  os << "parent  = " << p.str() << std::endl;
  os << "name    = " <<  "'" << Name() << "'" << std::endl;
  os << "file    = " << "'" << _filename << "'" << std::endl;
  os << "children= " << GetNumberOfChildren() << std::endl;
  os << "visible = " << IsShown() << std::endl;
  os << "pos     = " << GetPosition().Repr() << std::endl;
  os << "rot     = " << GetRotation().Repr() << std::endl;
  os << "scale   = " << GetScale().Repr() << std::endl;
  return os.str();
}
*/
